package org.jsola.hr.helper;

import org.jsola.common.SafeKit;
import org.jsola.hr.dto.AttendanceSallaryTemplateAddDTO;
import org.jsola.hr.dto.AttendanceSallaryTemplateUpdateDTO;
import org.jsola.hr.entity.AttendanceSallaryTemplateDO;
import org.jsola.hr.query.AttendanceSallaryTemplateQuery;
import org.jsola.hr.service.IAttendanceSallaryTemplateService;
import org.jsola.hr.vo.AttendanceSallaryTemplateVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 考勤工资模板表
 *
 * @author zhr
 */
@Component
public class AttendanceSallaryTemplateTestHelper extends BaseTestHelper {
    
    @Autowired
    private IAttendanceSallaryTemplateService attendanceSallaryTemplateService;

    /**
     * 生成add测试数据
     * @return AttendanceSallaryTemplateAddDTO
     */
    public AttendanceSallaryTemplateAddDTO getAttendanceSallaryTemplateAddDTO(){
        AttendanceSallaryTemplateAddDTO attendanceSallaryTemplateAddDTO = new AttendanceSallaryTemplateAddDTO();
        attendanceSallaryTemplateAddDTO.setCompanyId(getRandomValue("varchar",50));
        attendanceSallaryTemplateAddDTO.setTemplateName(getRandomValue("varchar",120));
        attendanceSallaryTemplateAddDTO.setYear(SafeKit.getInteger(getRandomValue("int",10)));
        attendanceSallaryTemplateAddDTO.setMonth(SafeKit.getInteger(getRandomValue("int",10)));
        return attendanceSallaryTemplateAddDTO;
    }


    /**
     * 生成update测试数据
     * @return AttendanceSallaryTemplateUpdateDTO
     */
    public AttendanceSallaryTemplateUpdateDTO getAttendanceSallaryTemplateUpdateDTO(AttendanceSallaryTemplateVO attendanceSallaryTemplateVO){
        return attendanceSallaryTemplateService.selectDOById(attendanceSallaryTemplateVO.getId(), SITE_ID).to(AttendanceSallaryTemplateUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return AttendanceSallaryTemplateQuery
     */
    public AttendanceSallaryTemplateQuery getAttendanceSallaryTemplateQuery() {
        AttendanceSallaryTemplateQuery attendanceSallaryTemplateQuery = new AttendanceSallaryTemplateQuery();
        List<AttendanceSallaryTemplateDO> attendanceSallaryTemplateDOList = attendanceSallaryTemplateService.list(new AttendanceSallaryTemplateDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(attendanceSallaryTemplateDOList)) {
            AttendanceSallaryTemplateDO attendanceSallaryTemplateDO = attendanceSallaryTemplateDOList.get(0);
            attendanceSallaryTemplateQuery = attendanceSallaryTemplateDO.to(AttendanceSallaryTemplateQuery.class);
        }
        return attendanceSallaryTemplateQuery;
    }

    /**
     * 保存示例
     * @return AttendanceSallaryTemplateVO
     */
    public AttendanceSallaryTemplateVO saveAttendanceSallaryTemplateExample(){
        AttendanceSallaryTemplateAddDTO addDTO = this.getAttendanceSallaryTemplateAddDTO();
        AttendanceSallaryTemplateVO attendanceSallaryTemplateVO = attendanceSallaryTemplateService.save(addDTO,buildTokenUser());
        return attendanceSallaryTemplateVO;
    }


}

